package com.cpj.bsyyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpj.bsyyzx.entity.Bed;
import com.cpj.bsyyzx.entity.BedRecord;
import com.cpj.bsyyzx.service.IBedRecordService;
import com.cpj.bsyyzx.service.IBedService;
import com.cpj.bsyyzx.util.CommonResult;
import net.sf.jsqlparser.statement.select.AllColumns;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/bed")
public class BedController {

    @Autowired
    IBedService bedService;
    @Autowired
    IBedRecordService bedRecordService;
    @RequestMapping("list")
    CommonResult list(Page page, @ModelAttribute("bed")Bed bed){
        page=bedService.pageList(page,bed);
        return CommonResult.success(page);
    }

    @RequestMapping("floor")
    CommonResult floor(Integer floor){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("floor",floor);
        return CommonResult.success(bedService.list(wrapper));
    }

    @RequestMapping("count")
    CommonResult count(){
        HashMap<String, Integer> map = bedService.AllCount();
        return CommonResult.success(map);
    }

    @RequestMapping("getlist")
    CommonResult getlist(){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("status",0);
        return CommonResult.success(bedService.list(wrapper));
    }

    @RequestMapping("findByCondition")
    CommonResult findByCondition(Page page,String ConditionName,String ConditionValue){
        if (ConditionName==null||ConditionName==""||ConditionValue==null||ConditionValue==""){
            page=bedService.pageList(page,null);
            return CommonResult.success(page);
        }
        if("user_name".equals(ConditionName)){
            List<BedRecord> list=bedRecordService.selectFind(ConditionValue);
            page=bedService.selectFindNums(list);
            return CommonResult.success(page);
        }
        page.setSize(15);
        page=bedService.selectFind(page,ConditionValue);
        return CommonResult.success(page);
    }

}
